package com.lcf.system.controller;

import com.lcf.framework.annotation.PermissionCheck;
import com.lcf.framework.enums.PermissionEnum;
import com.lcf.system.vo.permission.PermissionVO;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;
import static com.lcf.framework.enums.PermissionEnum.*;

/**
 * 权限
 *
 * @author lcf
 * @since 2025-06-17 21:14:49
 */
@Tag(name = "权限")
@RestController
@RequestMapping("permission")
public class PermissionController {
    /**
     * 获取全部权限列表
     */
    @Operation(summary = "获取全部权限列表")
    @PermissionCheck(SYS_PERMISSION_LIST)
    @GetMapping("list")
    public List<PermissionVO> list() {
        List<PermissionVO> resultList = new ArrayList<>();

        Arrays.stream(PermissionEnum.values()).collect(Collectors.groupingBy(PermissionEnum::getType))
                .forEach((type, permissionList) -> resultList.add(new PermissionVO(type, permissionList)));

        return resultList;
    }
}
